-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add suggestions with fuzzy text search when no relationship is found #2583
Conversation
4a6610f
to
91cf5b5
Compare
91cf5b5
to
51774f5
Compare
else (<> "' instead of '" <> parent <> "'.") <$> suggestParent | ||
where | ||
findParent = HM.lookup (QualifiedIdentifier schema parent, schema) allRels | ||
fuzzySetOfParents = Fuzzy.fromList [qiName (fst p) | p <- HM.keys allRels, snd p == schema] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is expensive if allRels
is big, in which case perhaps the hint could be disabled by looking at the map length?
Maybe this could be tested with the apflora schema, by doing time curl ..
on a request with bad names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In apflora, allRels
has a size of 305. These are the times that I get:
-
Relationship is found (no fuzzy search):
$ curl -w "%{time_total}s" -s "http://localhost:3000/ziel?select=ap(*)"
Response:
[]
Times:
0.002485s 0.002125s
-
Relationship not found (fuzzy search for parent)
$ curl -w "%{time_total}s" -s "http://localhost:3000/ziels?select=ap(*)"
Response:
{ "code": "PGRST200", "details": "Searched for a foreign key relationship between 'ziels' and 'ap' in the schema 'apflora', but no matches were found.", "hint": "Perhaps you meant 'ziel' instead of 'ziels'.", "message": "Could not find a relationship between 'ziels' and 'ap' in the schema cache" }
Times:
0.072776s 0.056077s
-
Relationship not found (fuzzy search for child)
$ curl -w "%{time_total}s" -s "http://localhost:3000/ziel?select=app(*)"
Response:
{ "code": "PGRST200", "details": "Searched for a foreign key relationship between 'ziel' and 'app' in the schema 'apflora', but no matches were found.", "hint": "Perhaps you meant 'ap' instead of 'app'.", "message": "Could not find a relationship between 'ziel' and 'app' in the schema cache" }
Times:
0.035553s 0.027014s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(fuzzy search for parent)
0.072776s
0.056077s
(fuzzy search for child)
0.035553s
0.027014s
So parent takes longer than child because it searches on the full allRels
, while child only searches on the relationships that have parent. Makes sense.
src/PostgREST/Error.hs
Outdated
-- If no relationship is found between a parent and a child, then it looks for the parent first. | ||
-- If the parent is not found then it does a fuzzy search to all the parents in the schema cache and | ||
-- gives the best match as suggestion. Otherwise, it does a fuzzy search to all the corresponding children | ||
-- of that parent and gives the best match as suggestion. If both are found, then no suggestion is given. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I'm understanding this.
If no rel is found:
- Looks for parent suggestions if parent not found
- Looks for child suggestions if children not found and parent is found
- No suggestions if both are found(
Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if both are found then there's an error with the hint, which is more complex to look for.
That one is really tricky and likely not worth it. Good that you didn't pursue it further. |
Closes #2569
Contemplating two options:
parent
orchild
one at a time. If no parent is found, then suggest the closest match and stop there, otherwise, continue looking for the child and suggest its closest match.Suggest bothparent
andchild
, if neither is found then suggest the closest relationship between them.Done so far: